package org.telluriumsource.ui.widget.dojo.object;

import demo.tellurium.framework.BaseDojoWidget 

import org.json.simple.JSONObject;

/**
 * Tellurium Widget object for the Dojo CheckBox widget
 *
 * @author Roger Xu (roger.xu.2007@gmail.com)
 *
 * Date: Apr 21, 2010
 * 
 */
class Button extends BaseDojoWidget {

    private static final String WIDGET_NAME = Button.class.getSimpleName();

    private Map attributes = [:];

    @Override
    public String getWidgetName() {
        return WIDGET_NAME;
    }

    @Override
    public JSONObject toJSON() {
        return buildJSON() {jso ->
            jso.put(UI_TYPE, NAMESPACE + "_" + getWidgetName());
        }
    }

    @Override
    public void defineWidget() {
        def clocator = [tag: "span", class: "dijitButton"];
        clocator.putAll(this.attributes);

        ui.Container(uid: "${WIDGET_NAME}") {
            Container(uid: "DijitButton", clocator: clocator, respond: ["click", "mouseDown", "mouseEnter", "mouseLeave"]) {
                Container(uid: "ButtonNode", clocator: [tag: "span", class: "dijitButtonNode"]) {
                    Container(uid: "ButtonContents", clocator: [tag: "button"]) {
                        Span(uid: "ButtonText", clocator: [class: "dijitButtonText"])
                    }
                }
            }
        }
    }

    public void clickButton() {
        def button = "${WIDGET_NAME}.DijitButton";

        click button
    }
}